package com.tea.funct.controller;

import com.tea.common.annotation.Log;
import com.tea.common.core.controller.BaseController;
import com.tea.common.core.domain.AjaxResult;
import com.tea.common.core.page.TableDataInfo;
import com.tea.common.enums.BusinessType;
import com.tea.common.utils.poi.ExcelUtil;
import com.tea.funct.domain.TeaRenew;
import com.tea.funct.service.ITeaRenewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员续费产品Controller
 *
 * @author Sophia
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/funct/renew")
public class TeaRenewController extends BaseController {
    @Autowired
    private ITeaRenewService teaRenewService;

    /**
     * 查询会员续费产品列表
     */
    @PreAuthorize("@ss.hasPermi('funct:renew:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaRenew teaRenew) {
        startPage();
        List<TeaRenew> list = teaRenewService.selectTeaRenewList(teaRenew);
        return getDataTable(list);
    }

    /**
     * 查询所有会员续费产品列表
     */
    @PreAuthorize("@ss.hasPermi('funct:renew:list')")
    @GetMapping("/listAllRenew")
    public TableDataInfo listAllRenew() {
        List<TeaRenew> list = teaRenewService.selectTeaRenewList(null);
        return getDataTable(list);
    }

    /**
     * 导出会员续费产品列表
     */
    @PreAuthorize("@ss.hasPermi('funct:renew:export')")
    @Log(title = "会员续费产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaRenew teaRenew) {
        List<TeaRenew> list = teaRenewService.selectTeaRenewList(teaRenew);
        ExcelUtil<TeaRenew> util = new ExcelUtil<TeaRenew>(TeaRenew.class);
        util.exportExcel(response, list, "会员续费产品数据");
    }

    /**
     * 获取会员续费产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('funct:renew:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(teaRenewService.selectTeaRenewById(id));
    }

    /**
     * 新增会员续费产品
     */
    @PreAuthorize("@ss.hasPermi('funct:renew:add')")
    @Log(title = "会员续费产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaRenew teaRenew) {
        return toAjax(teaRenewService.insertTeaRenew(teaRenew));
    }

    /**
     * 修改会员续费产品
     */
    @PreAuthorize("@ss.hasPermi('funct:renew:edit')")
    @Log(title = "会员续费产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaRenew teaRenew) {
        return toAjax(teaRenewService.updateTeaRenew(teaRenew));
    }

    /**
     * 删除会员续费产品
     */
    @PreAuthorize("@ss.hasPermi('funct:renew:remove')")
    @Log(title = "会员续费产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(teaRenewService.deleteTeaRenewByIds(ids));
    }
}
